export default class extends think.BaseController {
    
        /**
         * 单元网格立案数
         */
        async getBGIDCaseAction() {
            let aj = think.ajaxJson();
            const AreaService = this.service('overallmerit/AreaService');
            const data = {
                cycle:Number(this.get('cycle')),
                rangeDate:this.get('rangeDate'),
                BGID:this.get('BGID[]')
            };
            const res = await AreaService.getBGIDCase(data);
            if (res&&res.error) {
                aj.success = false;
                aj.msg = '查询失败';
            } else {
                aj.result = res;
            }
            return this.json(aj);
    
        }
        /**
         * 条件统计查询区域立案数
         * 
         * @returns 
         */
        async queryAllAreaDataAction() {
            let aj = think.ajaxJson();
            let data = {
                level:Number(this.get('level')),
                cycle:Number(this.get('cycle')),
                rangeDate:this.get('rangeDate'),
                area_code:this.get('area_code[]'),
                BGID:this.get('BGID[]'),
            }
            const AreaService = this.service('overallmerit/AreaService');
            const res = await AreaService.getAreaData(data);
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return this.json(aj);
        }


    /**
     * 获取街道，社区
     *param    type(string) 查询的类型(street-街道，community-社区，cell-单元网格
     *param    area_coed(array) 可选 所属区域编码
     *param is_include_parent(0,1) 查询是否包含父级（0-查询不包含父级，1-查询包含父级） 默认为1
     * @returns
     */
    async getStreetOrCommunityAction() {
        let aj = think.ajaxJson();
        let data = {
            type:this.post('type'),
            area_coed:this.post('area_coed'),
            is_include_parent:this.post('is_include_parent')?this.post('is_include_parent'):1,
        }
        const AreaService = this.service('overallmerit/AreaService');
        if(data.type==='street'){
            const res = await AreaService.getStreet(data);
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
        }else if(data.type==='community'){
            const res = await AreaService.getCommunity(data);
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
        }else{
            aj.success = false;
            aj.msg = '查询失败';
        }

        return this.json(aj);
    }
    /**
     * 获取区域单元网格树

     * @returns
     */
    async getCellTreeAction() {
        let aj = think.ajaxJson();
        const AreaService = this.service('overallmerit/AreaService');
            const res = await AreaService.getCellTree();
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }

        return this.json(aj);
     }
    }